from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, BadData
from django.conf import settings

from meiduo.utils.response_code import RETCODE

def generate_mobile_signature(dict):
    """加密手机号"""
    serializer = Serializer(settings.SECRET_KEY,RETCODE.CODETIME)
    # data = {'mobile':mobile}
    mobile_sign = serializer.dumps(dict)
    return mobile_sign.decode()


def check_mobile_signature(mobile_sign):
    """解密手机号"""

    serializer = Serializer(settings.SECRET_KEY,RETCODE.CODETIME)

    try:
        dict = serializer.loads(mobile_sign)
    except BadData:
        return None
    return dict